package com.hongye.app.model;

import com.jfinal.plugin.activerecord.Model;

public class ShoppingCartModel extends Model<ShoppingCartModel>{

	private static final long serialVersionUID = -800185170698946608L;
	
	public static final ShoppingCartModel dao=new ShoppingCartModel();

	/**
	 * 下订单删除购物车
	 * @author lifuqiang
	 * 2017-1-10
	 * @param phone
	 * @param gid
	 * @return
	 */
	public static boolean removeshoppingcart(String phone, Object gid){
		boolean boo = false;
		String sql = "select * from shoppingcart where phone = '"+phone+"' and goods_id = "+gid+"";
		ShoppingCartModel cart = dao.findFirst(sql);
		if(cart != null){
			if(new ShoppingCartModel().deleteById(cart.get("id"))){
				boo = true;
			}
		}
		return boo;
	}
	
	/**
	 * 得到购物车中  某商品的数量
	 * @author liushaomin
	 * 2017年7月12日
	 * @param phone
	 * @param goodsid
	 * @return
	 */
	public static int shoppingcart_goodsnum(String phone, int goodsid){
		String sql = "select * from shoppingcart where phone = '"+phone+"' and goods_id = "+ goodsid +"";
		ShoppingCartModel cart = dao.findFirst(sql);
		return cart.getInt("num");
	}
	
}
